package cm.studapp.actIndo;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.TextView;
import cm.studapp.R;
import cm.studapp.database.DbManager;
import cm.studapp.helpers.ButtonHelper;
import cm.studapp.helpers.TimeHelper;
import cm.studapp.InitStudApp;

public class ActRepDesc extends Activity{
	ButtonHelper bHelp;
	LinearLayout parentLayout;
	DbManager db;
	TimeHelper th;
	Cursor signatureData;
	int idAct;
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.rep_act_desc);
        idAct=getIntent().getExtras().getInt("idAct");
		initComponents();
		initViews();
	}
	
	public void initComponents(){
		db=new DbManager(this);
		signatureData=db.getRepActData(idAct);
		th = new TimeHelper();
		bHelp = new ButtonHelper(this);
	}
	
	public ActRepDesc() {
		// TODO Auto-generated constructor stub
	}

	public void initViews(){
		parentLayout=(LinearLayout)findViewById(R.id.repActDescLL_modules);
		
		TextView nm = (TextView)findViewById(R.id.RepActDescTv_name);
		TextView lu =(TextView)findViewById(R.id.RepActDescTv_lugar);
		TextView ob =(TextView)findViewById(R.id.RepActDescTv_obs);
		
		while (signatureData.moveToNext()){
			String eventName=signatureData.getString(1);
			String tipo = signatureData.getString(2);
			String modo = signatureData.getString(3);
			String lugar = signatureData.getString(4);
			String obs = signatureData.getString(5);
			
			nm.setText(eventName);
			lu.setText(lugar);
			ob.setText(obs);
		}
		
		Cursor modsData = db.getWeekModules(idAct);
		
		//Ciclo para poblar los modulos de tareas:
		while(modsData.moveToNext()){
			RelativeLayout child = (RelativeLayout)getLayoutInflater().inflate(R.layout.rep_act_module_elem, null);
			LinearLayout.LayoutParams paramChild = new
					LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
			paramChild.leftMargin = 10;
			paramChild.rightMargin = 10;
			paramChild.bottomMargin = 2;
			child.setLayoutParams(paramChild);
			
			TextView dia = (TextView)child.getChildAt(3);
				dia.setText(th.millisToHumanDay(modsData.getLong(2)));
				
			TextView initHour = (TextView)child.getChildAt(2);
				initHour.setText(th.millisToHour(modsData.getLong(2)));
				
			TextView endHour = (TextView)child.getChildAt(0);
				endHour.setText(th.millisToHour(modsData.getLong(3)));
			
			parentLayout.addView(child);
		}
			/*
			RelativeLayout child = (RelativeLayout)getLayoutInflater().inflate(R.layout.rep_act_module_elem, null);
			
			LinearLayout.LayoutParams paramChild = new
					LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
			paramChild.leftMargin = 10;
			paramChild.rightMargin = 10;
			paramChild.bottomMargin = 2;
			child.setLayoutParams(paramChild);
			
			
			RelativeLayout child2 = (RelativeLayout)getLayoutInflater().inflate(R.layout.rep_act_module_elem, null);
			child2.setLayoutParams(paramChild);
			parentLayout.addView(child);
			parentLayout.addView(child2);
			
			*/
		
		}
	
	
}
